package org.nowcoder.leetcode.arrays;

import java.util.Arrays;

/**
 * Title  : 1046. Last Stone Weight
 * Source : https://leetcode.cn/problems/last-stone-weight/description/
 * Author : XrazYang
 * Date   : 2024-1-19
 */

public class LeetCode_1046 {
    public int lastStoneWeight(int[] stones) {
        int n = stones.length;
        if (n == 1) return stones[0];
        Arrays.sort(stones);
        while (stones[n - 2] != 0) {
            stones[n - 1] = stones[n - 1] - stones[n - 2];
            stones[n - 2] = 0;
            Arrays.sort(stones);
        }
        return stones[n - 1];
    }
}
